# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: script_1.py
@time: 2024/10/23 19:02 
@desc: 

"""
import os
from urllib.parse import quote

from sdk.utils.util_times import TimeProcess


class Solution(object):
    """

    """

    def __init__(self):
        self.desc = f"script1_统计文件行数"
        print(self.desc)

    def process(self, data):
        """

        :return:
        """
        nums = 0
        input_file = data["input_file"]
        with open(input_file, "r") as fp:
            for i in fp:
                nums += 1

        file_content = f"文件{input_file},总行数:{nums}"
        tp = TimeProcess()
        download_path = "static/download"
        os.makedirs(download_path, exist_ok=True)
        download_file = f'{download_path}/result_{self.desc}_{tp.get_normal_date()}.txt'

        with open(download_file, "w", encoding="utf-8") as fp:
            fp.write(file_content)

        data["ScriptResults"] = f"result_{self.desc}_{tp.get_normal_date()}.txt"
        data["Desc"] = self.desc

        return data
